<template>
	<view class="share-demo">
		<image class="logo-img" src="../static/share/logo.png" mode="widthFix"></image>
		<view class="loto-tips">
			新鲜食材
			<text>·</text>
			一分抢购
			<text>·</text>
			0元起送
			<text>·</text>
			下单30分钟送达
		</view>
		<view class="main">
			<view class="card">
				<view class="ttip">
					<view class="ttip-text">
						手动截图分享
					</view>
				</view>
				<view class="header">
					<image :src="userInfo.avatarUrl" mode="widthFix"></image>
					<text>{{userInfo.nickname}}</text>
				</view>
				<view class="photo">
					<image class="shop" :src="goods.img" mode="widthFix"></image>
					<view class="bottom">
						<image class="bottom-img" src="../static/share/test.png" mode="widthFix"></image>
						<view class="price">
							<text>￥</text>
							{{goods.stockDto.price / 100}}
						</view>
					</view>
				</view>
				<view class="card-bottom">
					<view class="card-bottom-left">
						<view class="title">{{goods.title}}</view>
						<view>
							<view class="flex">
								<view class="btn">
									限时秒杀
								</view>
							</view>
							<view class="price-map">
								<view class="price-map-price">
									<text>￥</text>
									<text> {{goods.stockDto.price / 100}}</text>
								</view>
								<text class="orgin">￥{{ goods.originalPrice / 100 }}</text>
							</view>
						</view>
					</view>
					<view class="card-bottom-right">
						<image :src="qrCode" mode="widthFix"></image>
						<text>长按识别二维码</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		mapGetters
	} from 'vuex'
	export default {
		components: {},
		computed: {
			...mapGetters({
				userInfo: "getUserInfo",
				storageId: "storageId"
			}),
		},
		data() {
			return {
				goods: {},
				qrCode: '',
				yaoqingma: ''
			}
		},
		onLoad(options) {
			const item = JSON.parse(decodeURIComponent(options.goods))
			this.goods = item
			this.yaoqingma = options.yaoqingma
			this.init()
		},
		methods: {
			init() {
				let query = `c=${this.yaoqingma}&id=${this.goods.id}&s=${this.storageId}&gid=`
				query += this.goods.groupShop ? this.goods.groupShop.id : ''
				console.log(query)
				const params = {
					path: '/pages/product/detail',
					query: decodeURIComponent(query),
					userId: this.userInfo.id,
					spuId: this.goods.id,
					yaoqingma: this.yaoqingma,
					gid: this.goods.groupShop ? this.goods.groupShop.id : ''
				}
				this.$api
					.request('goods', 'shareCommodityInfo', params)
					.then(res => {
						// this.cartNum = res.data;
						const {
							data: {
								wxMinImg
							}
						} = res
						this.qrCode = wxMinImg
					})
					.catch(err => {
						this.$api.msg('请求失败，请稍后再试');
					});
			}
		},
	}
</script>
<style lang="scss" scoped>
	.flex {
		display: flex;
	}

	.share-demo {
		width: 750rpx;
		min-height: 100vh;
		background: linear-gradient(30deg, #36B542, #36B542);
		display: flex;
		flex-direction: column;
		align-items: center;
		color: #FFFFFF;
		font-size: 12px;

		.logo-img {
			width: 200rpx;
		}

		.loto-tips {
			margin-top: 25rpx;

			text {
				font-weight: bold;
				padding: 0 8rpx;
			}
		}

		.main {
			// flex: 1;
			width: 700rpx;
			padding-bottom: 30rpx;
			margin-top: 30rpx;

			.card {
				background-color: #FFFFFF;
				height: 100%;
				width: 100%;
				padding: 20rpx;
				border-radius: 20rpx;
				box-sizing: border-box;
				position: relative;

				.ttip {
					width: 100%;
					position: absolute;
					bottom: 0;
					display: flex;
					justify-content: center;

					&-text {
						background-color: #36B542;
						padding: 10rpx 25rpx;
						border-top-left-radius: 15rpx;
						border-top-right-radius: 15rpx;
					}
				}

				.header {
					display: flex;
					align-items: center;
					color: #000000;
					border-bottom: 1rpx solid #f2f2f2;
					padding-bottom: 20rpx;

					image {
						width: 110rpx;
						border-radius: 50%;
						margin-right: 20rpx;
					}

					text {
						font-weight: bold;
						font-size: 15px;
					}
				}

				.photo {
					position: relative;

					.shop {
						width: 100%;
						border-radius: 15rpx;
					}

					.bottom {
						position: absolute;
						bottom: 0;
						width: 100%;

						&-img {
							width: 100%;
						}

						.price {
							position: absolute;
							bottom: 0;
							font-size: 24px;
							font-weight: bold;
							width: 250rpx;
							text-align: center;
							line-height: 140rpx;

							text {
								font-size: 18px;
								padding-right: 5rpx;
							}
						}
					}
				}

				&-bottom {
					display: flex;
					width: 100%;
					justify-content: space-between;
					padding: 30rpx 20rpx 20rpx 20rpx;
					box-sizing: border-box;

					image {
						width: 160rpx;
					}

					&-left {
						flex: 1;
						color: #333333;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.title {
							width: 420rpx;
							font-size: 16px;
							font-weight: bold;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							-o-text-overflow: ellipsis;
						}

						.btn {
							background-color: #36B542;
							color: #FFFFFF;
							font-size: 10px;
							padding: 10rpx 20rpx;
							border-radius: 8rpx;
							margin-bottom: 15rpx;
						}

						.price-map {
							display: flex;
							align-items: center;
							color: #36B542;

							.price-map-price {
								text {
									&:first-child {
										font-size: 12px;
									}

									&:last-child {
										font-size: 24px;
										font-weight: bold;
									}
								}
							}

							.orgin {
								margin-left: 15rpx;
								font-size: 12px;
								color: #999999;
								text-decoration: line-through;
							}
						}
					}

					&-right {
						display: flex;
						align-items: center;
						flex-direction: column;
						color: #333333;
						font-size: 11px;

						text {
							margin-top: 20rpx;
						}
					}
				}
			}
		}
	}
</style>
